<template>
	<view class="padd-box">
		<view class="top-box flexWrap" v-if="orderList.length!=0">
			<view class="top-left">
				<view class="room-box">
					<view class="store-info"><text>{{doorInfo.equipment_name}}</text>{{doorInfo.shop_name||'--'}}</view>
					<view class="time">{{doorInfo.service_date||'加载中...'}} {{doorInfo.start_time||'加载中...'}}～{{doorInfo.end_time||'加载中...'}}</view>
				</view>
				<view class="img">
					<image src="../../static/home/mjImg.png"></image>
				</view>
			</view>
			<view class="mj-img">
				<image src="../../static/home/mjImg.png"></image>
			</view>
		</view>
		<view class="open-box flexWrap">
			<view class="open-item" @tap="openBigDoor()" v-if="shop_name&&orderList.length!=0">
				<view class="name">大门</view>
				<view class="operation-box flexWrap">
					<view class="open-btn flexWarpColumn">
						<text>开门</text>
					</view>
					<view class="operation-img">
						<image src="../../static/home/open.png"></image>
					</view>
				</view>
			</view>
			<view class="open-item" v-for="(item,index) in orderList" :key="index" @tap="openRoomDoor(item.store_equipment_id)">
				<view class="name">{{item.store_equipment_name}}</view>
				<view class="operation-box flexWrap">
					<view class="open-btn flexWarpColumn">
						<text>开门</text>
					</view>
					<view class="operation-img">
						<image src="../../static/home/open.png"></image>
					</view>
				</view>
			</view>
		</view>
		<view class="empty-box flexWarpCenterColumn" v-if="orderList.length==0">
			<image src="../../static/order/mj.png" class="empty-image"></image>
			<view class="empty-tips">这里空空如也！</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				doorInfo:{
					shop_name:""
				},
				orderList:[],
				store_id:"",
				damen:"",
				token:"",
				shop_name:""
			};
		},
		onLoad(ops) {
			this.store_id=ops.store_id||uni.getStorageSync('store_id')
			this.token=ops.token||uni.getStorageSync('token')
			this.store_equipment_id=ops.store_equipment_id
			this.getDoorList();
		},
		methods:{
			// 获取包房信息
			getDoorList(){
				this.$request.post(this.$api.doorList, {
					store_id:this.store_id,
					token:this.token
				}, {}).then(res => {
					if (res.code==1) {
						let {
							data = {}
						} = res;
						let newArray = data.order
						if(newArray.length!=0){
							for (let i in newArray) {
								newArray[i].createtime = this.$tools.formatDate(newArray[i].createtime, 1)
								newArray[i].service_start_time = this.$tools.formatDate(newArray[i].service_start_time,
									0)
								newArray[i].service_end_time = this.$tools.formatDate(newArray[i].service_end_time, 0)
								newArray[i].service_date = newArray[i].service_start_time.split(' ')[0]
								newArray[i].start_time = newArray[i].service_start_time.split(' ')[1]
								newArray[i].end_time = newArray[i].service_end_time.split(' ')[1]
							}
							this.doorInfo={
								equipment_name:newArray[0].store_equipment_name,
								shop_name:data.damen.shop_name||"",
								service_date:newArray[0].service_date,
								start_time:newArray[0].start_time,
								end_time:newArray[0].end_time
							}
							this.orderList=newArray
						}
						if(data.damen.shop_name){
							this.shop_name=data.damen.shop_name
						}
					}
				})
			},
			// 开大门
			openBigDoor(){
				uni.showLoading({
					title:'开门中，请稍等',
					mask:true
				})
				this.$request.post(this.$api.openBigDoor, {
					store_id:this.store_id,
					token:this.token
				}, {}).then(res => {
					if (res.code==1) {
						this.$tools.hideLoading()
						this.$tools.showToast('开门成功')
					}
				}).finally(() => {
					setTimeout(()=>{
						this.$tools.hideLoading()
					}, 1000)
				})
			},
			// 开包房门
			openRoomDoor(store_equipment_id){
				uni.showLoading({
					title:'开门中，请稍等',
					mask:true
				})
				this.$request.post(this.$api.openRoomDoor, {
					store_id:this.store_id,
					store_equipment_id:store_equipment_id,
					token:this.token
				}, {}).then(res => {
					if (res.code==1) {
						this.$tools.hideLoading()
						this.$tools.showToast('开门成功')
					}
				}).finally(() => {
					setTimeout(()=>{
						this.$tools.hideLoading()
					}, 1000)
				})
			}
		}
	}
</script>

<style lang="scss">
	.padd-box{
		padding: 38rpx;
	}
	.empty-box{
		margin-bottom: 64upx;
		.empty-image{
			width: 400upx;
			height: 400upx;
		}
		.empty-tips{
			font-size: 24upx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 34upx;
			color: #FFFFFF;
		}
	}
	.top-box{
		height: 188rpx;
		background: #fff;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 28rpx;
		.room-box{
			.store-info{
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #6e6e6e;
				text{
					font-size: 36rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #333;
					margin-right: 10rpx;
				}
			}
			.time{
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #333;
				margin-top: 20rpx;
			}
		}
		.mj-img{
			width: 232rpx;
			height: 232rpx;
		}
	}
	.open-box{
		margin-top: 36rpx;
		flex-wrap: wrap;
		.open-item{
			width: 264rpx;
			height: 278rpx;
			background: linear-gradient(1deg, #FFFFFF 0%, #F5FFEA 100%);
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			padding: 28rpx;
			margin-bottom: 30rpx;
			.name{
				font-size: 36rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #333;
			}
			.operation-box{
				margin-top: 18rpx;
				.open-btn{
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #50AB6E;
				}
				.operation-img{
					width: 134rpx;
					height: 190rpx;
					flex: none;
				}
			}
		}
	}
</style>
